
package com.avrio.json;

// <editor-fold defaultstate="collapsed" desc="import">
import java.io.IOException;
// </editor-fold>

@SuppressWarnings("serial")
public class JsonLiteral extends JsonValue {

    private final String value;

// <editor-fold defaultstate="collapsed" desc="JsonLiteral()">

    public JsonLiteral(String value) {
        this.value = value;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="write()">

    @Override
    protected void write(JsonWriter writer) throws IOException {
        writer.write(value);
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="toString()">

    @Override
    public String toString() {
        return value;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="asBoolean()">

    @Override
    public boolean asBoolean() {
        return isBoolean() ? isTrue() : super.asBoolean();
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="isNull()">

    @Override
    public boolean isNull() {
        return this == NULL;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="isBoolean()">

    @Override
    public boolean isBoolean() {
        return this == TRUE || this == FALSE;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="isTrue()">

    @Override
    public boolean isTrue() {
        return this == TRUE;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="isFalse()">

    @Override
    public boolean isFalse() {
        return this == FALSE;
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="hashCode()">

    @Override
    public int hashCode() {
        return value.hashCode();
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="equals()">

    @Override
    public boolean equals(Object object) {

        if(this == object) {
            return true;
        }
        if(object == null) {
            return false;
        }
        if(getClass() != object.getClass()) {
            return false;
        }

        JsonLiteral other = (JsonLiteral)object;
        return value.equals(other.value);
    }
// </editor-fold>

}
